<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *奖励记录
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['sent']=1;
	if(!empty($_RQ['tasktitle'])){
		$params['tasktitle like']='%'.trim($_RQ['tasktitle']).'%';
		$return['params']['tasktitle']=$_RQ['tasktitle'];
	} 
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_inclock_task_reward',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$task=$this->pdo_get('task_list',array('id'=>$item['taskid'],'uniacid'=>$_SESSION['uniacid']));
			$item['type']=$item['type']?:0;
			$item['rewarddesc']='奖励';
			$reward=json_decode($task['reward'],true);
			$credit_types=credit_types();
			foreach($reward as $key=>$value){
					if(strpos($key,'credit') !== false && $value>0){
						$type=substr($key, -1);
						$item['rewarddesc'].='['.$value.$credit_types[$type].'] ';
					}
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'奖励记录'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'tasktitle','title'=>'任务名称','type'=>'string'),
			array('name'=>'type','title'=>'任务类型','type'=>'radio','options'=>'tasktype'),
			array('name'=>'member','title'=>'奖励人','type'=>'member'),
			array('name'=>'sendtime','title'=>'奖励时间','type'=>'time'),
			array('name'=>'gettime','title'=>'领取时间','type'=>'time'),
			array('name'=>'rewarddesc','title'=>'奖励','type'=>'string'),
			array('name'=>'sent','title'=>'任务状态','type'=>'radio','options'=>'sent'),
		)),
		'search'=>array(
			array('name'=>'tasktitle','title'=>'任务名称','type'=>'string','width'=>'40'),
		)
	);
	$return['sent']=array('0'=>'未领取','1'=>'已领取');
	$return['reward_type']=array('credit1'=>'积分','credit2'=>'余额','red'=>'红包','reward_coupon'=>'优惠券','reward_goods'=>'商品');
	$return['tasktype']=$this->task_types;
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_inclock_task_record',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
